import {students} from "./mongo_student"
import {teachers, admins, donators} from "./mongo_non_student"

var err = {
  error_no: 2,
  error_msg: "内部错误，请联系杜思聪～"
}

var get_student_info = (studentNo, res) => {
  students.find({
    studentNo: {$in: studentNo.split(",")}
  }, (error, docs) => {
    if(error){
      res.send(err)
    }else{
      res.send({
        type: 1,
        error_no: 1,
        error_msg: "ok",
        docs: docs
      })
    }
  })
}

var get_teacher_info = (teacherNo, res) => {
  teachers.findOne({
    teacherNo: teacherNo
  }, (error, doc) => {
    if(error){
      res.send(err)
    }else{
      res.send({
        type: 2,
        error_no: 1,
        error_msg: "ok",
        doc: doc
      })
    }
  })
}

var get_admin_info = (adminNo, res) => {
  admins.findOne({
    adminNo: adminNo
  }, (error, doc) => {
    if(error){
      res.send(err)
    }else{
      res.send({
        type: 3,
        error_no: 1,
        error_msg: "ok",
        doc: doc
      })
    }
  })
}

var get_donator_info = (donatorNo, res) => {
  donators.findOne({
    donatorNo: donatorNo
  }, (error, doc) => {
    if(error){
      res.send(err)
    }else{
      res.send({
        type: 4,
        error_no: 1,
        error_msg: "ok",
        doc: doc
      })
    }
  })
}

var getUserInfo = (kind, id, res) => {
  switch (kind) {
    case '1':
      return get_student_info(id, res)
      break;
    case '2':
      return get_teacher_info(id, res)
      break;
    case '3':
      return get_admin_info(id, res)
      break;
    case '4':
      return get_donator_info(id, res)
      break;
    default:

  }
}

module.exports = {
  getUserInfo:getUserInfo
}
